﻿using System;
public class Node<T>
{
    public T Data { get; set; }
    public Node<T> Next { get; set; }

    public Node(T data)
    {
        Data = data;
        Next = null;
    }
}

public class LinkedList<T>
{
    private Node<T> head;

    public void Add(T data)
    {
        Node<T> newNode = new Node<T>(data);
        if (head == null)
        {
            head = newNode;
        }
        else
        {
            Node<T> current = head;
            while (current.Next != null)
            {
                current = current.Next;
            }
            current.Next = newNode;
        }
    }

    public void ForEach(Action<T> action)
    {
        Node<T> current = head;
        while (current != null)
        {
            action(current.Data);
            current = current.Next;
        }
    }

    public T Max(Func<T, T, bool> comparer)
    {
        if (head == null)
        {
            throw new InvalidOperationException("empty");
        }

        Node<T> current = head;
        T max = current.Data;

        while (current != null)
        {
            if (comparer(current.Data, max))
            {
                max = current.Data;
            }
            current = current.Next;
        }

        return max;
    }

    public T Min(Func<T, T, bool> comparer)
    {
        if (head == null)
        {
            throw new InvalidOperationException("empty");
        }

        Node<T> current = head;
        T min = current.Data;

        while (current != null)
        {
            if (comparer(current.Data, min))
            {
                min = current.Data;
            }
            current = current.Next;
        }

        return min;
    }

    public T Sum(Func<T, T, T> accumulator)
    {
        if (head == null)
        {
            throw new InvalidOperationException("empty");
        }

        Node<T> current = head;
        T sum = current.Data;

        while (current.Next != null)
        {
            current = current.Next;
            sum = accumulator(sum, current.Data);
        }

        return sum;
    }
}

class Program
{
    static void Main()
    {
        LinkedList<int> linkedList = new LinkedList<int>();
        int n = Convert.ToInt32(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            linkedList.Add(Convert.ToInt32(Console.ReadLine()));
        }

        Console.WriteLine("LinkedList elements:");
        linkedList.ForEach(Console.WriteLine);

        int max = linkedList.Max((a, b) => a > b);
        int min = linkedList.Min((a, b) => a < b);
        int sum = linkedList.Sum((a, b) => a + b);

        Console.WriteLine($"Max: {max}");
        Console.WriteLine($"Min: {min}");
        Console.WriteLine($"Sum: {sum}");
    }
}
